package com.example.demo.controller;

import com.example.demo.entity.Instorage;
import com.example.demo.service.InstorageService;
import com.example.demo.util.RestBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/instorages")
public class InstorageController {

    @Autowired
    private InstorageService instorageService;

    @PostMapping
    public RestBean<Instorage> createInstorage(@RequestBody Instorage instorage) {
        int result = instorageService.createInstorage(instorage);
        return result == 1 ?
                RestBean.success(instorage) : // 直接返回实体对象
                RestBean.failure(400, "创建失败");
    }

    @GetMapping("/storage/{sid}")
    public RestBean<List<Instorage>> getByStorage(@PathVariable Integer sid) {
        return RestBean.success(instorageService.findInstoragesByStorageId(sid));
    }
}